import {ElMessage, ElMessageBox} from "element-plus";

let timer: NodeJS.Timeout;

/**
 * 防抖
 * @param fn 方法
 * @param duration 时间
 */
export function debounce(fn: Function, duration: number) {
    if (timer)
        clearTimeout(timer)
    timer = setTimeout(() => {
        fn()
    }, duration)

}

export function deletedMessage(then: Function, c?: Function) {
    ElMessageBox.confirm("确认删除吗", "删除", {
        type: "warning",
        cancelButtonText: '取消',
        confirmButtonText: "确定"
    }).then(async () => {
        await then()
    })
        .catch(async () => {
            if (c)
                await c()
            else {
                ElMessage.info("取消")
            }
        })
}